package com.ronipl.createtabs;

import java.util.List;

import com.ronipl.createtabs.model.valueobjects.IUserActionListItem;
import com.ronipl.createtabs.model.valueobjects.StarredAction;
import com.ronipl.createtabs.utilities.dummy.DummyMyRequestList;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * A simple {@link android.support.v4.app.Fragment} subclass.
 * 
 */
public class FragmentC extends Fragment implements OnClickListener {
	
	Button MyRequestRefreshBtn;
	TextView myRequestHeaderText;
	ListView list;
	public FragmentC() {
		// Required empty public constructor
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		View rootView = inflater.inflate(R.layout.fragment_c, container, false);
		
		MyRequestRefreshBtn = (Button)rootView.findViewById(R.id.RefreshMyRequest);
		MyRequestRefreshBtn.setOnClickListener(this);
		
		Typeface cus_font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/opensansregular.ttf");
		myRequestHeaderText = (TextView)rootView.findViewById(R.id.header_bg_wrapper_myrequest);
		MyRequestRefreshBtn.setTypeface(cus_font);
		myRequestHeaderText.setTypeface(cus_font);
		
		list = (ListView)rootView.findViewById(R.id.list_my_request);
		list.setAdapter(new MyRequestBaseAdapter(this));
		
		return rootView;
	}

	@Override
	public void onClick(View arg0) {
		// onclick listener		
		RefreshMyRequestData();
		
	}
	
	public void RefreshMyRequestData(){
		Toast.makeText(getActivity(), "Refresh handler for My Request", Toast.LENGTH_LONG).show();
	}

}

class MyRequestBaseAdapter extends BaseAdapter{
	
	List<IUserActionListItem>list;
	
	Context context;
	
	public MyRequestBaseAdapter(FragmentC fragmentC){
		
		context = (Context)fragmentC.getActivity();
		
		list = DummyMyRequestList.getDummyMyRequestList();
		
		
	}

	@Override
	public int getCount() {
		
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}
	
	class MyRequestViewHolder {
		
		//CONTENT COMING FROM JAVA
		TextView header;
		TextView SubHeaderDataB;
		TextView headerInfo;
		TextView headerInfoDataB;
		TextView ContentTitle;
		TextView Content;
		TextView FooterTitle;
		TextView FooterContent;
		
		public MyRequestViewHolder(View view){
			
			headerInfo = (TextView)view.findViewById(R.id.header_info);
			headerInfoDataB = (TextView)view.findViewById(R.id.header_info_data_b);
			ContentTitle = (TextView)view.findViewById(R.id.content_tItle);
			Content = (TextView)view.findViewById(R.id.contents);
			FooterTitle = (TextView)view.findViewById(R.id.footer_title);
			FooterContent = (TextView)view.findViewById(R.id.footer_content);
			
		}
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View row = convertView;
		MyRequestViewHolder holder= null;
		
		if(row == null){
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.my_request_view_list, parent, false);
			holder = new MyRequestViewHolder(row);
			row.setTag(holder);	
			
		}
		else 
		{		
			holder = (MyRequestViewHolder) row.getTag();			
		}
		
		IUserActionListItem data = list.get(position);
		
		holder.headerInfo.setText(data.getHeaderInfo());
		holder.headerInfoDataB.setText(data.getHeaderInfoDataB());
		holder.ContentTitle.setText(data.getContentTitle());
		holder.Content.setText(data.getContent());
		holder.FooterTitle.setText(data.getFooterTitle());
		holder.FooterContent.setText(data.getFooterContent());
		
		Typeface cus_font = Typeface.createFromAsset(context.getAssets(), "fonts/opensansregular.ttf");
		holder.headerInfo.setTypeface(cus_font);
		holder.headerInfoDataB.setTypeface(cus_font);
		holder.ContentTitle.setTypeface(cus_font);
		holder.Content.setTypeface(cus_font);
		holder.FooterTitle.setTypeface(cus_font);
		holder.FooterContent.setTypeface(cus_font);
		
		return row;
	}
	
}

